{% extends 'base.twig' %}
 {% block style %}
     <link href="template/plugins/fileinput/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
     <script src="template/plugins/fileinput/js/fileinput.js" type="text/javascript"></script>
     <!--简体中文-->
     <script src="template/plugins/fileinput/js/locales/zh.js" type="text/javascript"></script>
     <link rel="stylesheet" href="template/plugins//dialog/dist/ui-dialog.css">
 {% endblock %}
{% block content %}
<section id="main-content">
    <section class="wrapper">
        <div class="row mt">
            <div class="col-lg-12">
                <div class="form-panel">
                    <h4 class="mb text-info">
                        {% if  gid %}
                            <i class="fa fa-edit"></i> 修改焦点图
                        {% else %}
                            <i class="fa fa-plus"></i> 新增焦点图
                        {% endif %}
                        <button class="text-right btn btn-success pull-right" id="submit"  {% if readonly is null %} onclick="$('#form').submit();" {% endif  %} ><i class="fa fa-save"></i> 保 存 </button>
                    </h4>
                    {% if error %}
        
                        {% for e in error %}
                            <p class="text-danger bg-warning text-center" style="padding: 5px 0"> ** {{ e.title }} **</p>
                        {% endfor %}
    
                    {% endif %}
    
                    <form id='form' name="form" class="form-horizontal style-form" method="post" action="index_focus.php?&act=save">
                        <input type="hidden" name="id" value="{{ id }}">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" > 选择产品 </label>
                            <div class="col-sm-3">
                                 <input type="text" class="form-control" name="title" readonly value="{{ title }}">
                                 <input type="hidden" class="form-control" name="product_id" required value="{{ product_id }}">
                            </div>
                            <div class="col-sm-2">
                                <button type="button" class ="btn btn-success selectGoods">选择产品</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" > 域名 </label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" name="domain" readonly value="{{ domain }}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" > 上传图片 </label>
                            <div class="col-sm-4">
                               {% if thumb %}
                                   <img src="{{ thumb |replace({"img.stosz.com":"imgcn.stosz.com"}) }}" width="150">
                                {% endif %}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" >  </label>
                            <div class="col-sm-4">
                                <input type="file" class="file-1a" name="upfile">
                                <input  type="hidden"  name="thumb" id="thumb" value="{{ thumb }}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" > 描述 </label>
                            <div class="col-sm-4">
                                <textarea class="form-control" style="height: 100px" name="desc">{{ desc }}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" > 排序<br/><i class="text-danger">【数值越大越靠前】</i> </label>
                            <div class="col-sm-4">
                                <input type="number" class="form-control" name="sort" value="{{ sort }}" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 text-center" > </label>
                            <div class="col-sm-4" id="showImg">
                                
                            </div>
                        </div>
                           <input type="hidden" name="act" value="save">
                    </form>
                </div>
                
            </div>
        </div>
    </section>
</section>
    <script src="template/plugins/dialog/dist/dialog-plus-min.js?"></script>
    <script language="javascript" src="template/plugins//validform/Validform_v5.3.2_min.js"></script>
    <script type="text/javascript">
        highlight_subnav('index_focus.php?');
        $(function(){
            
            $('.file-1a').fileinput({
                        language: 'zh',
                        allowedFileExtensions : ['jpg', 'png','gif'],
                        showCaption: false,
                        showUpload:false,
                        maxFileCount:1 ,
                        uploadUrl: 'qiniu_um.php?type=focus',
                    }).on("filebatchselected", function(event, files) {
                        $(this).fileinput("upload");
                    }).on("fileuploaded", function(event, data) {
                        res = data.response ;
                        if(res.state=="SUCCESS")
                        {
                            $('#thumb').val(res.url) ;
                            return true ;
                        }
                        alert('上传失败') ;
                        return false ;
                    }).on('filesuccessremove', function(event, key) { 
                         $('#thumb').val('') ;
                    }).on('filecleared', function(event, key) { 
                         $('#thumb').val('') ;
                    });
        //选择商品
          $(document).on('click','button.selectGoods',function(){
            var _url= "product.php?act=publicProduct&self=1";
             dialog({
                id:'_selectGoods_',
                title:'选择商品',
                url:_url,
                width:1000,
                height:900,
                data:'no'
            }).showModal();
        });
        });
        function setGoodsOne(_arr){
            console.log(_arr) ;
            var _id=_arr['_id'];
            var _title = _arr['_title'];
            var _domain = _arr['_domain'];
            $("input[name='title']").val(_title) ;
            $("input[name='product_id']").val(_id);
            $("input[name='domain']").val(_domain);
            dialog.get('_selectGoods_').close();
        }
      
    </script>
{% endblock %}